package org.libermundi.theorcs.chronicles.model.message.impl;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.libermundi.theorcs.chronicles.ChronicleConstants;
import org.libermundi.theorcs.chronicles.model.Persona;
import org.libermundi.theorcs.chronicles.model.message.Target;
import org.libermundi.theorcs.chronicles.model.message.TargetRole;
import org.libermundi.theorcs.core.model.base.BasicEntity;

/**
 * The InternalEmailTarget  has a role and specify if its InternalEmail has been read
 *
 */
@Entity(name="InternalEmailTarget")
@Table(name=ChronicleConstants.TBL_INTERNAL_EMAIL_TARGET)
public class InternalEmailTarget extends BasicEntity implements Target<Persona>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1461128885981925776L;
	public static final String PROP_ROLE = "role";
	public static final String PROP_SEEN = "seen";

	private TargetRole _role;

	private Persona _persona;
	
	private InternalEmail _internalEmail;

	/**
	 * The message has been seen or not
	 */
	private boolean _seen;
	
	public InternalEmailTarget() {
		super();
	}

	public InternalEmailTarget(Persona persona, TargetRole role) {
		super();
		this._persona = persona;
		this._role = role;
		//by default the message has not been read
		this._seen = false;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="personaId")
	@Override
	public Persona getPersona() {
		return _persona;
	}
	
	public void setPersona(Persona persona) {
		this._persona = persona;
	}
	
	@Enumerated(EnumType.STRING)
	@Column(name=PROP_ROLE,length=3,nullable=false)
	@Override
	public TargetRole getRole() {
		return _role;
	}

	public void setRole(TargetRole role) {
		this._role = role;
	}
	
	@Basic
	@Column(name=PROP_SEEN)
	public boolean isRead() {
		return _seen;
	}

	public void setRead(boolean read) {
		this._seen = read;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="internalEmailId")
	public InternalEmail getInternalEmail() {
		return _internalEmail;
	}

	public void setInternalEmail(InternalEmail _internalEmail) {
		this._internalEmail = _internalEmail;
	}

}
